import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:xindong/models/gift/xindong_gift_class.dart';
import 'package:xindong/widgets/gift/xindong_songli_controller.dart';
import 'package:xindong/widgets/gift/view/xindong_songli_grid_view_item.dart';

class XinDongSongLiGridView extends StatelessWidget {
  final List? dataList;

  const XinDongSongLiGridView({Key? key, required this.dataList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final XinDongGiftClass? selectGift = XinDongSongLiController.to.selectGift;
    return AlignedGridView.count(
      itemCount: dataList?.length ?? 0,
      padding: const EdgeInsets.only(top: 10, bottom: 10),
      crossAxisCount: 4,
      mainAxisSpacing: 8,
      crossAxisSpacing: 0,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) {
        XinDongGiftClass model = dataList![index];
        bool selected = false;
        if (selectGift != null) {
          selected = (model.cate_id == selectGift.cate_id && model.id == selectGift.id);
        }
        return XinDongSongLiGridViewItem(
          model: dataList![index],
          selected: selected,
          onSelected: XinDongSongLiController.to.onTapSelectClass,
        );
      },
    );
  }
}
